<template>
  <el-dialog :visible.sync="showInfo" width="920px" :close-on-click-modal='false' :close-on-press-escape='false'
    top="10vh">
    <h2 slot="title" class="tx-c">项目详情</h2>
    <el-form autocomplete="off" label-width="125px" :model="info" class="form_flex">
      <el-form-item v-for="(v, i) in headerList" :key="i" :label="v.label+'：'" class="mr8">
        <div v-if="v.prop === 'departments_id'" class="block_cell">{{info.department?info.department.name:'无'}}</div>
        <div v-else-if="v.prop === 'leader_id'" class="block_cell">{{info.leader_info?info.leader_info.name:"无"}}</div>
        <div v-else-if="v.prop === 'complete_id'" class="block_cell">{{objToStr(info.complete_name)||'无'}}</div>
        <div v-else-if="v.prop === 'review_status'" class="block_cell">{{info.status}}<span
            v-if="info.review_comment">：{{info.review_comment}}</span> </div>
        <div v-else-if="v.prop === 'disciplines_id'" class="block_cell">{{info.discipline?info.discipline.name:'无'}}
        </div>
        <div v-else-if="v.prop === 'leader_type'" class="block_cell">{{leaderTypeObj[info.leader_type] || '无'}}</div>
        <div v-else-if="v.prop === 'contract_amount' || v.prop === 'manage_amount'" class="block_cell">
          {{info[v.prop]}}万元</div>
        <div v-else class="block_cell">{{info[v.prop] || '无'}}</div>
      </el-form-item>
    </el-form>
    <h3 class="mb8 f-18">项目附件：</h3>
    <div v-if="info.attachment && info.attachment.length > 0" class="mb16">
      <div class="pl16">
        <el-image :z-index='3000' v-for="item in echoFiles(info.attachment,true)" :key='item.id' class="details_image"
          :src="uploadUrl + item.file_path" :preview-src-list="srcList(echoFiles(info.attachment,true))">
        </el-image>
      </div>
      <div class="mt8">
        <p class="inspectionFile" v-for="v in echoFiles(info.attachment,false)" :key='"attachment" + v.id'>
          <span class="shou f-16" @click="uploadFiles(v.file_path,v.file_name)"><i
              class="iconfont icon-ziyuan"></i>{{v.file_name}}</span>
        </p>
      </div>
    </div>
    <div v-else class="mb16 c-9 pl16 f-16">暂无项目附件</div>
    <h3 class="mb8 f-18">已上传验收报告：</h3>
    <div v-if="info.accept_file && info.accept_file.length > 0" class="mb16">
      <div class="pl16">
        <el-image :z-index='3000' v-for="item in echoFiles(info.accept_file,true)" :key='item.id' class="details_image"
          :src="uploadUrl + item.file_path" :preview-src-list="srcList(echoFiles(info.accept_file,true))">
        </el-image>
      </div>
      <div class="mt8">
        <p class="inspectionFile" v-for="v in echoFiles(info.accept_file,false)" :key='"accept_file" + v.id'>
          <span class="shou f-16" @click="uploadFiles(v.file_path,v.file_name)"><i
              class="iconfont icon-ziyuan"></i>{{v.file_name}}</span>
        </p>
      </div>
    </div>
    <div v-else class="mb16 c-9 pl16 f-16">暂无验收报告</div>
  </el-dialog>
</template>

<script>
  import {headerList} from '../js/international'
  import {leaderTypeObj} from "@/assets/js"
  import {ApiupLoadFiles} from '@/api'
  import {isIMage} from "@/utils/test";
  import {objToStr} from "@/utils/index";
  import {uploadUrl} from '@/api/request'
  export default {
    props: {
      info: {
        default: () => ({})
      }
    },
    data() {
      return {
        objToStr,
        uploadUrl: uploadUrl(),
        headerList,
        leaderTypeObj,
        showInfo: false
      }
    },
    methods: {
      echoFiles(arr = [], flag = true) {
        return arr.filter(item => isIMage(item.file_name) === flag)
      },
      srcList(arr = []) {
        return arr.map(item => this.uploadUrl + item.file_path)
      },
      uploadFiles(url, name) {
        ApiupLoadFiles(url).then(res => {
          let a = document.createElement("a")
          a.href = URL.createObjectURL(res)
          a.download = name
          a.click()
          URL.revokeObjectURL(a.href)
        })
      },
    }
  }
</script>